<template>
	<view class="content">
		<view class="content-top">
			<view class='cell-group margin-cell-group'>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>当前U</view>
					</view>
					<view class='cell-item-bd'>
						<text class="cell-bd-view">￥{{wallet.user_money}}</text>
					</view>
				</view>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>转账U</view>
					</view>
					<view class='cell-item-bd'>
						<input class='cell-bd-input' placeholder='请输入要转账U的数量' v-model="money" focus type="digit"></input>
					</view>
				</view>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>对方账号</view>
					</view>
					<view class='cell-item-bd'>
						<input class='cell-bd-input' placeholder='请输入对方账号' v-model="iPhone" focus type="digit"></input>
					</view>
				</view>
				<!-- <view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>转账规则</view>
					</view>
					<view class='cell-item-bd'>
						<view class='cell-hd-title'>转账手续费2%</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="button-bottom">
			<button class="btn btn-square btn-b" hover-class="btn-hover2" @click="navigateToHandle">去转账</button>
		</view>
	</view>
</template>

<script>
	import {
		getWallet,transferPoints
	} from '@/api/user';
	export default {
		data() {
			return {
				// user: {}, // 用户信息
				money: '', // 转账积分
				wallet: {}, // 用户信息
				iPhone: ""
			}
		},
		onLoad() {
			this.getWallets()
		},
		methods: {
			// 获取用户信息
			getWallets() {
				getWallet().then(res => {
					if (res.code == 1) {
						this.wallet = res.data
						console.log(this.wallet)
					}
				});
			},
			// 去充值
			navigateToHandle() {
				if (!Number(this.money)) {
					// this.$common.errorToShow('请输入要充值的金额')
					uni.showToast({
						title: '请输入要转账的金额',
						duration: 2000,
						icon: "none"
					});
				} else if (!Number(this.iPhone)) {
					uni.showToast({
						title: '请输入手机号',
						duration: 2000,
						icon: "none"
					});
				} else {
					let data={
						points:this.money,
						mobile:this.iPhone
					}
					transferPoints(data).then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: res.msg,
								icon: "none"
							});
							setTimeout(function() {
								uni.redirectTo({
									url: "../user_wallet/user_wallet"
								})
							}, 2000);
						}
					});
					
				}
			}
		}
	}
</script>

<style>
	.user-head {
		height: 100upx;
	}

	.user-head-img {
		height: 90upx;
		width: 90upx;
		border-radius: 50%;
	}

	.cell-hd-title {
		color: #333;
	}

	.cell-item-bd {
		color: #666;
		font-size: 26upx;
	}

	.button-bottom .btn {
		width: 100%;
	}
</style>
